<?php

use think\migration\Migrator;
use think\migration\db\Column;

class AirQualityStationAqiRealtimeDay extends Migrator
{
    public function up()
    {
        $table = $this->table('air_quality_station_aqi_realtime_day');
        $table
            //step1:基本信息
            ->addColumn('region_id', 'integer', ['comment'=>'区域ID',])
            ->addColumn('station_id', 'integer', ['comment'=>'站点id',])

            //step2:时间
            ->addColumn('publish_time', 'datetime', ['comment'=>'发布时间',])
            ->addColumn('create_time', 'datetime', ['comment'=>'插入时间',])

            //step3:六参,iaqi用来计算首要污染物（天是参数的24小时的均值）
            //pm10
            ->addColumn('pm10', 'float', ['comment'=>'PM10',])
            ->addColumn('pm10_percent', 'decimal', ['precision' => 11, 'scale' => 2, 'default' => '0.00', 'comment'=>'PM10的占比',])
            ->addColumn('pm10_iaqi', 'float', ['limit' => 11, 'default' => '0', 'comment'=>'经过计算后得到的IAQI取整数',])
            ->addColumn('pm10_level', 'string', ['comment'=>'PM10的质量状况',])
            ->addColumn('pm10_color', 'string', ['limit' => 20,  'comment'=>'PM10质量状况对应的颜色值',])
            //pm25
            ->addColumn('pm25', 'float', ['comment'=>'PM2.5',])
            ->addColumn('pm25_iaqi', 'float', ['limit' => 11, 'default' => '0', 'comment'=>'经过计算后得到的IAQI取整数',])
            ->addColumn('pm25_percent', 'decimal', ['precision' => 11, 'scale' => 2, 'default' => '0.00', 'comment'=>'PM2.5的占比',])
            ->addColumn('pm25_level', 'string', ['comment'=>'PM2.5的质量状况',])
            ->addColumn('pm25_color', 'string', ['limit' => 20,  'comment'=>'PM2.5质量状况对应的颜色值',])
            //so2
            ->addColumn('so2', 'float', ['comment'=>'SO2',])
            ->addColumn('so2_percent', 'decimal', ['precision' => 11, 'scale' => 2, 'default' => '0.00', 'comment'=>'二氧化硫的占比',])
            ->addColumn('so2_iaqi', 'float', ['limit' => 11, 'default' => '0', 'comment'=>'经过计算后得到的IAQI取整数',])
            ->addColumn('so2_level', 'string', ['comment'=>'二氧化硫的质量状况',])
            ->addColumn('so2_color', 'string', ['limit' => 20,  'comment'=>'二氧化硫质量状况对应的颜色值',])
            //no2
            ->addColumn('no2', 'float', ['comment'=>'二氧化氮',])
            ->addColumn('no2_percent', 'decimal', ['precision' => 11, 'scale' => 2, 'default' => '0.00', 'comment'=>' 二氧化氮的占比',])
            ->addColumn('no2_iaqi', 'float', ['limit' => 11, 'default' => '0', 'comment'=>'经过计算后得到的IAQI取整数',])
            ->addColumn('no2_level', 'string', ['comment'=>' 二氧化氮的质量状况',])
            ->addColumn('no2_color', 'string', ['limit' => 20,  'comment'=>'二氧化氮质量状况对应的颜色值',])
            //co
            ->addColumn('co', 'float', ['comment'=>'一氧化碳',])
            ->addColumn('co_percent', 'decimal', ['precision' => 11, 'scale' => 2, 'default' => '0.00', 'comment'=>'一氧化碳的占比',])
            ->addColumn('co_iaqi', 'float', ['limit' => 11, 'default' => '0', 'comment'=>'经过计算后得到的IAQI取整数',])
            ->addColumn('co_level', 'string', ['comment'=>'一氧化碳的质量状况',])
            ->addColumn('co_color', 'string', ['limit' => 20,  'comment'=>'一氧化碳质量状况对应的颜色值',])
            //o3
            ->addColumn('o3', 'float', ['comment'=>'臭氧',])
            ->addColumn('o3_percent', 'decimal', ['precision' => 11, 'scale' => 2, 'default' => '0.00', 'comment'=>'臭氧的占比',])
            ->addColumn('o3_iaqi', 'float', ['limit' => 11, 'default' => '0', 'comment'=>'经过计算后得到的IAQI取整数',])
            ->addColumn('o3_level', 'string', ['comment'=>'臭氧的质量状况',])
            ->addColumn('o3_color', 'string', ['limit' => 20,  'comment'=>'臭氧质量状况对应的颜色值',])
            ->addColumn('o3_8hour', 'float', ['comment'=>'当天臭氧最大8小时的滑动平均值',])
            //step4:aqi
            ->addColumn('aqi', 'float', ['comment'=>'空气质量等级/空气质量指数',])
            ->addColumn('aqi_level', 'string', ['comment'=>'aqi污染情况：优0-50/良50-100/轻度100-150/中度150-200/重度200-300/严重300-500,超过500爆表不用体现',])
            ->addColumn('aqi_color', 'string', ['limit' => 20,  'comment'=>'空气质量等级对应的颜色值',])

            //其他
            ->setEngine('InnoDB')
            ->setComment('空气质量 - 站点 - AQI实际（天）')
            ->create();
    }
    
    public function down()
    {
        $this->dropTable('air_quality_station_aqi_realtime_day');
    }
}
